Msg("====Tool Restriction module initialized...\n")

local tools = {}
local found = false

function gSAM.GetTools()
	local ts = ents.FindByClass("gmod_tool")[1].Tool or nil
	if !found then
		if ts then
			for k,v in pairs(ts) do
				local name = v.Name or k
				table.insert(tools,{k,v.Name,GROUP_PLAYER})
			end
			found = true
		end
	end
end
hook.Add("Think","gSAM.GetTools",gSAM.GetTools)

function gSAM.ChangeToolGroup(tool,group)
	for k,v in pairs(tools) do
		if v[1] == tool then
			v[3] = group or GROUP_PLAYER
		end
	end
end

function gSAM.ToolUse(ply,tr,tool)
	for k,v in pairs(tools) do
		if v[1] == tool then
			if !(gSAM.GetPlayerGroup(ply) <= v[3]) then
				gSAM.HintPlayer(ply,"Tool "..v[2].." is disabled!")
				return false
			end
		end
	end
	return true
end
hook.Add("CanTool","gSAM.ToolUse",gSAM.ToolUse)
